package com.zmn.mcc.admin.controller.staff.staffperformance;


import com.zmn.mcc.model.entity.staff.McStaff;
import com.zmn.mcc.model.entity.staff.staffperformance.StaffPerformance;
import com.zmn.mcc.model.entity.staff.staffperformance.StaffPerformanceQuery;
import com.zmn.mcc.services.interfaces.staff.staffperformance.StaffPerformanceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 员工绩效基础查询Controller
 *
 * @author tanghongjun
 * @since 2020-05-14 11:15:18
 */
@RestController
@RequestMapping("/staff/staffperformance/")
public class StaffPerformanceListController extends StaffPerformanceBaseController {

    private Logger logger = LoggerFactory.getLogger(StaffPerformanceListController.class);

    @Resource
    private StaffPerformanceService staffPerformanceService;

    /**
     * 列表
     */
    @RequestMapping("/listByStaffId")
//    @RequiresPermissions("staff/stafffamily/list.action")
    public ModelAndView listByStaffId(@RequestParam(value = "staffId", defaultValue = "0") Integer staffId) {
        StaffPerformanceQuery query = new StaffPerformanceQuery();
        query.setStaffId(staffId);

        return this.list(query);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("staff/staffperformance/list.action")
    public ModelAndView list(@ModelAttribute StaffPerformanceQuery query) {
        if (Objects.isNull(query.getStaffId())) {
            logger.error("员工ID不能为空" + query.getStaffId());
            return null;
        }

        McStaff obj = staffService.findByKey(query.getStaffId());
        List<StaffPerformance> items = staffPerformanceService.listPageByQuery(query);

        ModelAndView mav = new ModelAndView("staff/staffperformance/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);
        mav.addObject("obj", obj);
        mav.addObject("flag", 7);

        return mav;
    }


    /**
     * 信息
     */
    @RequestMapping("/addEditView")
//    @RequiresPermissions("staff/staffperformance/addEditView.action")
    public ModelAndView info(@RequestParam(value = "performanceId", defaultValue = "0") Integer performanceId) {

        StaffPerformance staffPerformance;
        if (performanceId == 0) {
            staffPerformance = new StaffPerformance();
        } else {
            staffPerformance = staffPerformanceService.findById(performanceId);
        }

        ModelAndView mav = new ModelAndView("staff/staffperformance/detail");
        mav.addObject("staffPerformance", staffPerformance);

        return mav;
    }

}
